<?php
namespace Admin\Controller;
/**
 * 商品介绍编辑
 * User: linkwhy
 * Date: 2015/10/30
 * Time: 11:39
 */
class GoodsInfoController extends AdminController{

    public function index(){
        $id = I('get.id');
        !empty($id) ? $where = array('pid' => $id) : $where = array('pid' => 0);
        $list   = $this->lists('goods_info', $where);
        int_to_string($list);
        $this->assign('_list', $list);
        $this->assign('pid', !empty($id) ? $id : 0);
        $this->meta_title = '商品介绍编辑';
        $this->display();
    }

    public function add(){
        $this->meta_title = '新增商品介绍';
        $this->assign('pid', I('get.pid'));
        $this->assign('_class', $this->infotype());
        $this->display('update');
    }

    public function edit(){
        $dclass = M('goods_info');
        $data = $dclass->field(true)->where(array('id' => I('get.id')))->find();
        $data['pid'] = intval($data['pid']);
        $this->meta_title = '修改商品介绍';
        $this->assign('data', $data);
        $this->assign('pid', $data['pid']);
        $this->assign('_class', $this->infotype());
        $this->display('update');
    }

    private function infotype(){
        return M('goods_info')->field(true)->select();
    }
}